-
Notifications
You must be signed in to change notification settings - Fork 172
Laplace Transform #1590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Laplace Transform #1590
Conversation
…h no repeated roots)
…ving to do with constant distribution
unable to test on laptop. will test on different computer soon
…dOfFrogs/Symbolics.jl into ToriDell/symbolic-ode-solver
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1590 +/- ##
==========================================
+ Coverage 80.08% 80.53% +0.45%
==========================================
Files 53 58 +5
Lines 5358 5970 +612
==========================================
+ Hits 4291 4808 +517
- Misses 1067 1162 +95 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Reference to Ds replaced with Differential(s), as Ds was local variable in laplace
Helper function to unwrap derivatives of `f(t)` in `expr` with respect to the differential operator `Dt = Differential(t)`. Returns a tuple `(n, base_expr)`, where `n` is the order of the derivative and `base_expr` is the expression with the derivatives removed. If `expr` does not contain `f(t)` or its derivatives, returns `(0, expr)`. | ||
""" | ||
function unwrap_der(expr, Dt) | ||
reduce_rule = @rule Dt(~x) => ~x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Repeatedly creating @rule
in the recursive call and then matching it is pretty expensive. I'd recommend just doing
function reduce_rule(expr, Dt)
iscall(expr) && isequal(operation(expr), Dt) ? arguments(expr)[1] : nothing
end
end | ||
|
||
# takes into account fractions | ||
function _true_factors(expr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use SymbolicUtils.flatten_fractions
to handle nested fractions and then SymbolicUtils.numerators
to get the list of factors in the numerator and SymbolicUtils.denominators
to get the list of factors in the denominator. Make sure to unwrap
everything passed into those functions.
return isequal(expr, 0) | ||
end | ||
|
||
function _parse_trig(expr, t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment about @rule
in a function.
import DomainSets.ClosedInterval | ||
|
||
# from https://tutorial.math.lamar.edu/Classes/DE/Laplace_Table.aspx | ||
transform_rules(f, t, F, s) = Symbolics.Chain([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if SymbolicUtils.@cache
will play nicely with this. It could save a lot of time considering that this is called recursively. This also applies to the previous comments about @rule
in recursive functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, the laplace
function could have a keyword rules = nothing
. It then does
if rules === nothing
rules = transform_rules(f, t, F, s)
end
and passes rules
down to recursive calls. Again, this approach works for the similar previous comments and is arguably better than @cache
.
# t-derivative rule ((Dt^n)(f(t)) -> s^n*F(s) - s^(n-1)*f(0) - s^(n-2)*f'(0) - ... - f^(n-1)(0)) | ||
n, expr = unwrap_der(expr, Dt) | ||
if n != 0 && isequal(expr, f(t)) | ||
f0 = Symbolics.variables(:f0, 0:(n-1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use some unicode here to avoid name collisions?
@variables λ # eigenvalue | ||
v = variables(:v, 1:size(A, 1)) # vector of subscripted variables to represent eigenvector |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both of these should use unicode to avoid name collisions
Adds Laplace and inverse Laplace transforms based on linearity and rule tables. Planned use for solving ODEs.